package java6703.lesson13;

public class DrinkWater6703 {

    //声明int类型的私有变量waters，表示水桶中的水量
    static int waters;

    public static void main(String[] args) {
        //启动狗和猫两个线程运行drinking6703方法
        drinking6703();
    }

    //动物喝水方法drinking6703
    private static void drinking6703() {

        //用方法引用启动多线程
        DrinkWater6703.waters = 15;
        new Thread(DrinkWater6703::Water, "狗").start();
        new Thread(DrinkWater6703::Water, "猫").start();
    }

    static void Water() {

        String name = Thread.currentThread().getName();

        //循环喝水
        while (waters > 0) {

            if (name.equals("狗")) {
                //狗每次喝5个单位
                waters = waters - 5;
            } else if (name.equals("猫")) {

                //猫每次喝2个单位
                waters = waters - 2;
            }
            System.out.println(name + "已喝水，剩" + waters);
        }
        System.out.println(name + "请加水！！");
    }
}

class House implements Runnable {
    int waters;

    public House(int waters) {
        this.waters = waters;
    }

    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        while (waters > 0) {
            if (name.equals("狗")) {
                waters = waters - 5;
            } else if (name.equals("猫")) {
                waters = waters - 2;
            }
            System.out.println(name + "已喝水，剩" + waters);
        }
        System.out.println(name + "请加水！！");
    }
}